#ifndef QQ_APP_BAR
#define QQ_APP_BAR

#include <qabstractnativeeventfilter.h>
#include <qapplication.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qpropertyanimation.h>
#include <qscreen.h>
#include <qwidget.h>

#include <ElaIconButton.h>

#ifdef Q_OS_WIN
#include <Windows.h>
#include <dwmapi.h>
#include <windowsx.h>
#else Q_OS_LIUNX
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <QX11Info>
#endif

class QQAppBar : public QWidget, public QAbstractNativeEventFilter
{
	Q_OBJECT

public:
	enum AppBarHintType
	{
		NoButtonHint,
		MinimizeButtonHint,
		MaximizeButtonHint,
		CloseButtonHint,
		WindowsHint,
	};
	Q_ENUM(AppBarHintType)
		Q_DECLARE_FLAGS(AppBarHintTypes, AppBarHintType)
public:
	explicit QQAppBar(QWidget* parent = nullptr, AppBarHintType types = AppBarHintType::WindowsHint);
	~QQAppBar();
	void set_allow_drag(bool is_allow_drag);
	bool get_allow_drag() const;
	void set_allow_resize(bool is_allow_resize);
	bool get_allow_resize() const;
	void set_windows_flag(AppBarHintType type, bool isEnable = true);
	void set_windows_flags(AppBarHintTypes types);
	QQAppBar::AppBarHintTypes get_windows_flags();
	void set_windows_title(const QString& title, Qt::AlignmentFlag flag = Qt::AlignmentFlag::AlignCenter);
	void set_windows_icon(const QIcon& icon);

protected:
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
	bool nativeEventFilter(const QByteArray& eventType, void* message, qintptr* result) override;
#else
	bool nativeEventFilter(const QByteArray& eventType, void* message, long* result) override;
#endif
private:
	bool mouse_in_widget(QWidget* widget);
private:
	bool m_is_allow_drag;
	bool m_is_allow_resize;
	AppBarHintTypes m_types;
	WId m_wid;
	int m_margin;
	QIcon m_icon;
	QLabel* m_icon_label;
	QString m_title;
	QLabel* m_title_label;
	ElaIconButton* m_minimize_button;
	ElaIconButton* m_maximize_button;
	ElaIconButton* m_close_button;
};

#endif // QQ_APP_BAR
